namespace Microsoft.ServiceModel.Samples.Discovery
{
    using System;
    using System.Xml;
    using System.Collections.Generic;
    
    internal class FindCorrelator
    {
        Dictionary<UniqueId, FindContext> activeFindTable;

        public FindCorrelator()
        {
            this.activeFindTable = new Dictionary<UniqueId, FindContext>();
        }

        public void AddFind(FindContext context)
        {
            lock (this.activeFindTable)
            {
                this.activeFindTable.Add(context.FindId, context);
            }
        }

        public bool RemoveFind(FindContext context)
        {
            lock (this.activeFindTable)
            {
                return this.activeFindTable.Remove(context.FindId);
            }
        }

        public bool IsActive(FindContext context)
        {
            lock (this.activeFindTable)
            {
                return this.activeFindTable.ContainsKey(context.FindId);
            }
        }

        public FindContext LookupFind(UniqueId findId)
        {
            FindContext context = null;
            lock (this.activeFindTable)
            {
                this.activeFindTable.TryGetValue(findId, out context);
            }

            return context;
        }
    }
}
